// components/timer/timer.js
Component({
    externalClasses: [ "m-class" ],
    /**
   * 组件的属性列表
   */
    properties: {
        color: {
            type: Boolean,
            default: true
        },
        timeData: {
            // type: Object,
            observer(newVal, oldVal, changePath) {
                let that = this;
                if (newVal > 0) {
                    that.timer(newVal);
                    that.setData({
                        timing: newVal
                    });
                }
            }
        },
        timeStyle: {
            type: Object,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    ...newVal
                });
            }
        },
        kill_id: {
            type: String,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    kill_id: newVal
                });
            }
        }
    },
    /**
   * 组件的初始数据
   */
    data: {
        timing: 0,
        h: "00",
        m: "00",
        s: "00",
        height: 32,
        mainColor: "#FE3112"
    },
    lifetimes: {},
    /**
   * 组件的方法列表
   */
    methods: {
        timer(timing) {
            let that = this;
            var timer2 = null;
            // clearInterval(that.data.timer);
            // this.setData({\
                        timer2 = setInterval(function() {
                var day = 0, hour = 0, minute = 0, second = 0;
                //时间默认值
                                if (timing > 0) {
                    hour = Math.floor(timing / (60 * 60)) - day * 24;
                    minute = Math.floor(timing / 60) - day * 24 * 60 - hour * 60;
                    second = Math.floor(timing) - day * 24 * 60 * 60 - hour * 60 * 60 - minute * 60;
                }
                if (hour <= 9) hour = "0" + hour;
                if (minute <= 9) minute = "0" + minute;
                if (second <= 9) second = "0" + second;
                that.setData({
                    h: hour,
                    m: minute,
                    s: second,
                    timing: timing
                });
                timing--;
                if (timing < 0) {
                    clearInterval(timer2);
                }
            }, 1e3);
            // })
                },
        clearTimer() {
            clearInterval(this.data.timer);
        }
    }
});